package blockchain

import "qkl/block"

type BlocksChain struct {
	Blocks []*block.Block
}

func (bc *BlocksChain) AddBlock(data string) {
	newBlock := block.NewBlock(data, bc.Blocks[len(bc.Blocks)-1].Hash) //根据最后一个hush创建一个区块
	bc.Blocks = append(bc.Blocks, newBlock)

}

func NewBlocksChain() *BlocksChain {
	genesisBlock := GenesisBlock()
	return &BlocksChain{
		Blocks: []*block.Block{genesisBlock},
	}
}

func GenesisBlock() *block.Block {
	return block.NewBlock("Hello World", []byte{})
}
